import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

BLUE = [255, 0, 0]


image = cv.imread('image1.jpg')

replicate = cv.copyMakeBorder(image , 30, 30, 30, 30, cv.BORDER_REPLICATE)
reflect = cv.copyMakeBorder(image , 30, 30, 30, 30, cv.BORDER_REFLECT)
reflect301 = cv.copyMakeBorder(image , 30, 30, 30, 30, cv.BORDER_REFLECT_101)
wrap = cv.copyMakeBorder(image , 30, 30, 30, 30, cv.BORDER_WRAP)
constant = cv.copyMakeBorder(image , 30, 30, 30, 30, cv.BORDER_CONSTANT, value=BLUE)

plt.subplot(231), plt.imshow(image , 'gray'), plt.title('ORIGINAL')
plt.subplot(232), plt.imshow(replicate, 'gray'), plt.title('REPLICATE')
plt.subplot(233), plt.imshow(reflect, 'gray'), plt.title('REFLECT')
plt.subplot(234), plt.imshow(reflect301, 'gray'), plt.title('REFLECT_101')
plt.subplot(235), plt.imshow(wrap, 'gray'), plt.title('WRAP')
plt.subplot(236), plt.imshow(constant, 'gray'), plt.title('CONSTANT')
# 改变通道顺序
# plt.subplot(231), plt.imshow(image[..., ::-1], 'gray'), plt.title('ORIGINAL')
# plt.subplot(232), plt.imshow(replicate[..., ::-1], 'gray'), plt.title('REPLICATE')
# plt.subplot(233), plt.imshow(reflect[..., ::-1], 'gray'), plt.title('REFLECT')
# plt.subplot(234), plt.imshow(reflect301[..., ::-1], 'gray'), plt.title('REFLECT_101')
# plt.subplot(235), plt.imshow(wrap[..., ::-1], 'gray'), plt.title('WRAP')
# plt.subplot(236), plt.imshow(constant[..., ::-1], 'gray'), plt.title('CONSTANT')
plt.show()